/***************************************************************************
 *  Filename: controlsender.h
 *  Class: ControlSender
 *  
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/



#ifndef CONTROLSENDER_H
#define CONTROLSENDER_H

#include <QObject>
#include <QWaitCondition>
#include <QMutex>
#include <QtNetwork/QHostAddress>
#include <QtNetwork/QUdpSocket>

#include "messages.h"

class ControlSender : public QObject
{
    Q_OBJECT
public:
    explicit ControlSender(QObject *parent = 0);
    
signals:
    void stopped();
public slots:
    void runOnce();
    void sendInitSequence(int step);
    void updateCommands(float pitch, float roll, float tyaw, float tgaz);
    void setemergency();
    void takeoff();
    void land();
    void reset();
    void updateState(uint state);
    void startRunning();
private:
    quint32 dronestate;
    float phi;
    float theta;
    float gaz;
    float yaw;
    int sequence;
    bool abort;
    bool emergency;
    bool takingoff;
    bool landing;
    bool ready;
    uint input;
    QWaitCondition waitCondition;
    QTimer timer;
    QMutex mutex;
    QHostAddress localaddress;
    QUdpSocket *mysocket;
    QTime loopTimeKeeper;
//    QTime commandsTimeKeeper;
//    QTime statusTimeKeeper;
};

#endif // CONTROLSENDER_H
